"use strict";
const nodemailer = require("nodemailer");

// 创建发送邮件的对象
  let transporter = nodemailer.createTransport({
  service: 'qq', // 使用了内置传输发送邮件 查看支持列表：https://nodemailer.com/smtp/well-known/
    port: 465, //端口号
    secure: true, // true for 465, false for other ports
    auth: {
      user:'2820103217@qq.com',   //发送方
      pass: 'slrhnfrehkdpdfib',  
    }
  });

  function sendmail(mail,code){
      // 邮件信息
      let  mailObj={
        from: '"hello" <2820103217@qq.com>', // sender address
        to: mail, // list of receivers
        subject: "注册验证", // Subject line
        text: `您的验证码是${code}，有效期五分钟`, // plain text body
        //html: "<b>Hello world?</b>" // html body
      }
      return new Promise((resolve,reject)=>{
        transporter.sendMail(mailObj,(err,data)=>{
            if(err){
              reject(err)
            }else{
              resolve(data)
            }
        });
      })
      
  }
  module.exports={sendmail}